package cn.wolfcode.shop.cloud.web.advice;

import cn.wolfcode.shop.cloud.common.CommonControllerAdvice;
import cn.wolfcode.shop.cloud.common.Result;
import cn.wolfcode.shop.cloud.util.MemberCodeMsg;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MemberControllerAdvice extends CommonControllerAdvice {

    @ExceptionHandler
    public Result handlerParamException(BindException e) {
        String message = e.getAllErrors().get(0).getDefaultMessage();
        return new Result().error(MemberCodeMsg.PARAM_VALIDATION.format(message));
    }
}
